//
//  UIActionSheet+Extension.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/1.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#undef	UIActionSheet_key_clicked
#define UIActionSheet_key_clicked	"UIActionSheet.clicked"

#import "UIActionSheet+Extension.h"
#import <objc/runtime.h>

@implementation UIActionSheet (Extension)

- (void)handlerClickedButton:(UIActionSheet_block_self_index)aBlock
{
    self.delegate = self;
    objc_setAssociatedObject(self, UIActionSheet_key_clicked, aBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIActionSheet_block_self_index block = objc_getAssociatedObject(self, UIActionSheet_key_clicked);
    !block ? : block(actionSheet, buttonIndex);
}
//断开关联
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
   objc_setAssociatedObject(self, @selector(handlerClickedButton:), nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
